package com.dlut.java5;

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

/**
 * @Author: LiuHeng
 * @Description:
 * @Date: 2022-09-28 18:54
 */
public class T0929_HuaWei {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s1 = in.nextLine();
        String s2 = in.nextLine();
        String s3 = in.nextLine();
        int[] tree1 = new int[1010];
        int[] tree2 = new int[1010];

        int n=0,m=0,nrt;
        for (int i = 0; i < s1.length(); i++) {
            if (Character.isDigit(s1.charAt(i))){
                tree1[++n] = s1.charAt(i) - '0';
            }
        }
        nrt = 1;
        boolean fl = true;
        for (int i = 0; i < s2.length(); i++) {
            if (Character.isDigit(s2.charAt(i))){
                int r = s2.charAt(i) - '0';
                if (fl){
                    fl = false;
                    continue;
                }
                if (tree1[nrt << 1] == r)
                    nrt<<=1;
                else
                    nrt = nrt << 1 | 1;
            }
        }
        for (int i = 0; i < s3.length(); i++) {
            if (Character.isDigit(s3.charAt(i))){
                int r = s3.charAt(i) - '0';
                tree2[++m] = r;
            }
        }
        for (int i = 0; i <= m; i++) {
            if (tree2[i] > 0){
                tree1[fun(nrt,i)] = tree2[i];
            }
        }
        System.out.print("[");
        if (tree1[1]>0){
            System.out.print(tree1[1]);
        }
        for (int i = 2; i < 1010; i++) {
            if (tree1[i]>0){
                System.out.print(","+ tree1[i]);
            }
        }
        System.out.print("]");
    }
    static int[] sta = new int[1010];
    private static int fun(int nrt, int s) {
        int t =0;
        while (s!=1){
            sta[++t] = s%2;
            s>>=1;
        }
        for (int i = t;i>=1;i--){
            nrt = nrt<<1 | sta[i];
        }
        return nrt;
    }











    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int m = in.nextInt();
        int n = in.nextInt();
        int[][] a = new int[m][n];
        int[][] up = new int[m][n];
        int[][] le = new int[m][n];
        int[][] ri = new int[m][n];
        long[][] num = new long[m][n];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                num[i][j] = in.nextInt();
            }
        }



    }

    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Order[] orders = new Order[n];
        for (int i = 0; i < n; i++) {
            int num1 = in.nextInt();
            int num2 = in.nextInt();
            orders[i] = new Order(num1, num2);
        }
        Arrays.sort(orders);
        PriorityQueue<Integer> queue = new PriorityQueue<>((n1,m) -> m-n1);
        int cur=0;
        for(Order order : orders){
            int t = order.start;
            int d = order.end;
            if(cur+t<=d){
                cur+=t;
                queue.offer(t);
            }else if(!queue.isEmpty() && queue.peek()>t){
                cur -= queue.poll()-t;
                queue.offer(t);
            }
        }
        System.out.println(queue.size());
    }

    static class Order implements Comparable<Order>{
        int start;
        int end;
        public Order(int i, int j){
            start = i;
            end = j;
        }
        @Override
        public int compareTo(Order o) {

            return (end - o.end);
        }

    }
}
